const loginBtn = document.querySelector('#btn-login')
//1.提交用户登陆数据
async function postAccountData(){
    try {
        const form = document.querySelector('.login-form')
        let data = serialize(form, { hash: true, empty: true })
        console.log(data)
        
        let res = await axios({url:'/login',method:'POST',data:data})
        console.log(res.data)
        let {username,token} = res.data
        pxmu.success(res.message)
        if(res.message==='登录成功'){
            //1.保存token
            localStorage.setItem('username',username)
            localStorage.setItem('token',token)
            setTimeout(()=>{
            location.href=`./index.html?username=${data.username}`
            },1500)
        }
        
    } catch (error) {
        pxmu.fail('登陆失败')
    }
}
loginBtn.addEventListener('click',(e)=>{
    // e.preventDefault()
    postAccountData()
})
